package com.elective.courseselect.controller;

import com.elective.courseselect.entity.CommentEntity;
import com.elective.courseselect.service.CommentService;
import com.elective.courseselect.utils.PageUtils;
import com.elective.courseselect.utils.R;
import com.elective.status.StatusCode;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 评论标签
 *
 * @author lee
 * @email 943204006@qq.ccom
 * @date 2021-09-04 19:23:06
 */
@RestController
@RequestMapping("courseselect/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = commentService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		CommentEntity comment = commentService.getById(id);
        return R.ok().put("comment", comment);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody CommentEntity comment){
		commentService.save(comment);
        return R.ok("新增课程标签成功");
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody CommentEntity comment){
		commentService.updateById(comment);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		commentService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    //查询课程评论标签库
    @ApiOperation("查询课程评论标签库")
    @GetMapping("/searchAll")
    public R searchAll(){
        List<CommentEntity> list = commentService.list();
        return R.ok(StatusCode.OK,"查询课程评论标签库成功").put("list", list);
    }

}
